#ifndef RENDERER_H
#define RENDERER_H
#include "ProjectHeader.h"

class Renderer
{
private:
vertex3f Translation;		//Stores the translation of the camera from (0,0,0)
vertex3f Rotation;			//Stores the rotation of the scene
vertex3f Speed;				//Stores the speed that the scene is rotating at
//These three variables may be removed at some point and replaced with a camera system.

GLfloat LightAmbient[4];	// Ambient light
GLfloat LightDiffuse[4];	// Diffuse light
GLfloat LightPosition[4];	// Light Position
bool light;					// set lighting effects on/off
bool blend;					// set blending effects on/off
bool redrawStatics;

// Return Values: None; Updates VBOs held by OGL, and elementCount, vertCount. No error returns.
void UpdateVBOs();	//Updates any VBOs that need updated

// Return Values: Index into Texture[]; Error returns: any value <0 - errors in ERROR_ENUM. 0 never returned.
int LoadTexture(const char *File);	//Load a texture using soil; adds it to Texture[] and returns the index.

GLuint CurrentBoundTex;	//Stores OGL pointer of the currently bound texture; saves an OGL call by preventing unneccecary changes.
std::map<int, texCoord2f> TexCoords;	//maps internal texture coords to coordinates in a texAtlas; The atlas's index in Texture is also stored.
std::vector<GLenum> errors;	//used for debugging purposes; Stores any errors that OGL returns through glGetError
std::vector<GLuint> Texture;	//Stores OGL pointers to Texture Atlases
std::vector<std::vector<GLuint>> vboPointers;	//Stores OGL pointers to VBOs; The VBO at VBOs[t][a] is stored at vboPointers[t][a]
std::vector<std::vector<DrawEventPair>> DrawList;	//Stores fastDelegate pairs for drawing with; the first index is the type. 
std::vector<std::vector<std::vector<GLsizei>>> elementCount;	//Stores the number of vertexes in the VBO from a draw method

//A summery of what these containers are for:
//	light				- Bool value representing whether 
//	blend
//	redrawStatics
//	CurrentBoundTex
//
//	   TexCoords[i]			- Contains Texture Coordinates for each corner of the texture stored, as well as the index into Texture for the atlas
//		  errors[n]			- Contains any errors OGL outputs; used for debugging.
//		 Texture[a]			- Contains OGL pointers to texture atlases. It's used to convert between internal atlas numbers, and OGL textures
//	 vboPointers[t][a]		- Contains OGL pointers to VBOs. VBO at VBOs[t][a] is stored at vboPointers[t][a]
//		DrawList[t][o]		- Contains DrawEventPairs called to produce renderable geometry
//	elementCount[t][a][o]	- Contains a count of the number of elements contributed to the VBO at VBOs[t][a] by the drawer at DrawList[t][o]
//
//		t	means type; t is 1, 2 or 3, and can also be refered to through the enum DRAW_TYPE; 1 = STATIC, 2 = UPDATE_IF_DIRTY, and 3 = UPDATE_PER_FRAME.
//		a	means atlas; a is the texture atlas that textures are contained in. The relevent OGL pointer is stored at Texture[a].
//		o	means order; it has no specific relevenece, other than identifying individual DrawEventPairs in DrawList.
//		i	means internalTexNumber; it is used in draw methods to identify individual textures, independant of atlases and whatnot.
//		n	means number; it's not really important, and errors will probably be removed at some point - perhaps when I stop making them :P




public:

GLfloat xView;			// Shifts the view side to side; will be removed soon.
GLfloat depth;			// Depth into the screen; intially -5.0f
Renderer();				// Constructor

// Returns: 0 if successful. Error returns: an error value from ERROR_ENUM - TEX_LOAD_ERROR, GLEW_LOAD_ERROR, 
int InitGL();						//Sets up OGL; Called through a fastDelegate.

int DrawGLScene();		//Draws the scene; will update VBOs and call any relevent transform delegates too.

void ReSizeGLScene(GLsizei width, GLsizei height);	//Resizes the scene
void ReSizeGLScene(UINT msg, WPARAM wParam, LPARAM lParam);	// Overload; Called through a fastDelegate. Reads the message and resizes to the new window size.
bool RegisterDraw(DrawEventPair, enum DRAW_TYPE);			// Registers delegates to produce geometry, and apply transforms at draw time. 
bool RegisterDraw(DrawEvent_delegate, enum DRAW_TYPE);		// Overload; Registers a delegate to be called when drawing, without transforms.


GLvoid toggleLight();		//Turn lighting effects on/off
GLvoid toggleBlend();		//Turn blending effects on/off

const std::map<int, texCoord2f>& getTexCoords();	//Returns a const reference to the texture map

};
#endif